<?php
/**
*描述:拦截
*auth:李飞@天众科技
*time:2017/02/06
*/
namespace Admin\Controller;
use Think\Controller;
class InterceptedController extends CommonController {
	
	public function Intercepted() {
		$m=M('InterceptKey',C('DB_PRS'),C('DB_DEPOT'));
		$keylist=$m->select();
		$arr[0]['code']=0;
		$arr[0]['name']='未选择';
		foreach($keylist as $k=>$v){
			$arr[$k+1]['code']=$v['field_name'];
			$arr[$k+1]['name']=$v['name'];
		}
		$this->assign('keylist',$arr);
		$this->display();
	}
	//获取拦截列表
    public function get_intercepted() {
		$ck=A('CheckInput');
		//参数验证
        $val=I('val');
		$key=I('key');
		$status=I('status');
        $page=$ck->in('当前页','page','intval','1',0,0);
        $rows=$ck->in('每页记录数','rows','intval','',0,0);
		//排序
        $sort=$ck->in('排序','sort','cnennumstr','id',0,0);
        $order=$ck->in('规则','order','cnennumstr','desc',0,0);
		//搜索条件
		$map=array();
		
		!empty($val)?$map['val']=array('like','%'.$val.'%'):'';
		!empty($key)?$map['key']=array('like','%'.$key.'%'):'';
		
		//获取数据
        $data=getTable('Intercept',$map,$page,$rows,$sort,$order,$status);
		
        $this->ajaxReturn($data);
    }
	//添加拦截值
    public function interceptedAdd(){
		$m=M('Intercept',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit;
        $ck=A('CheckInput'); 
		$data['val']=I('val');
		$data['key']=I('key');
		$data['add_time']=time();
		$data['update_time']=time();
        $insertId=$m->add($data);
        if(!$insertId){
            $return['message']='添加失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='添加成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//更新拦截值
    public function interceptedSave(){
		$m=M('Intercept',C('DB_PRS'),C('DB_DEPOT'));
        if(!IS_POST) exit; 
        $ck=A('CheckInput');
		$data['val']=I('val');
		$data['key']=I('key');
		$data['update_time']=time();
        $map['id']=$ck->in('id','id','intval','',1,0);
		
        $result=$m->where($map)->save($data);
		
        if(false===$result){
            $return['message']='更新信息失败';
            $return['status']=false;
            $this->ajaxReturn($return);
        }else{
            $return['message']='更新信息成功!';
			$return['status']=true; 
			$this->ajaxReturn($return);
        }
    }
	//////////////////////////////////////////////////////
	//审核拦截值
    public function examineIntercepted(){
		$return=tableExamine('Intercept');
        $this->ajaxReturn($return);
    }
	//删除拦截值
    public function interceptedDel(){
		$return=tableDel('Intercept');
        $this->ajaxReturn($return);
    }
	//清空回收站拦截值
    public function interceptedClear(){
		$return=tableClear('Intercept');
        $this->ajaxReturn($return);
    }
	//恢复回收站数据拦截值
    public function interceptedUndo(){
		$return=tableUndo('Intercept');
        $this->ajaxReturn($return);
    }
}